package com.gxks.lhs.security;

import com.gxks.lhs.entity.Admin;
import com.gxks.lhs.security.UserDetails.SysAdminDetails;
import com.gxks.lhs.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class SysAdminDetailsService implements UserDetailsService {

    @Autowired
    private IAdminService adminService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Admin admin = adminService.selectByUsername(username);

        if (admin == null) {
            throw new UsernameNotFoundException("Admin not found with username: " + username);
        }
        UserDetails adminDetails = new SysAdminDetails(admin);
        return adminDetails;
    }
}